//
//  ZYSportSportingViewController.m
//  LoveSport
//
//  Created by 王朝阳 on 2016/11/8.
//  Copyright © 2016年 wangzhaoyang. All rights reserved.
//

#import "ZYSportSportingViewController.h"
#import "ZYSportMapViewController.h"

@interface ZYSportSportingViewController ()
/**
 运动地图控制器
 */
@property (nonatomic, strong) ZYSportMapViewController *mapViewController;//使用 strong 保证地图控制器不被释放
@property (weak, nonatomic) IBOutlet UIButton *mapButton;

@end

@implementation ZYSportSportingViewController
#pragma mark - 不要在此方法中设置子控件的 frame, 因为此方法中自动布局没有完成
- (void)viewDidLoad {
    [super viewDidLoad];

    [self setMapViewController];
    //
}
#pragma mark - 在此方法中设置子控件的 frame
- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    
    //设置指南针的 frame
    CGFloat x = _mapButton.center.x - _mapViewController.mapView.compassSize.width * 0.5;
    CGFloat y = _mapButton.center.y - _mapViewController.mapView.compassSize.height * 0.5;
    _mapViewController.mapView.compassOrigin = CGPointMake(x, y);
}
#pragma mark - 监听地图按钮的点击
- (IBAction)showMapViewController {

    //模态展现
    [self presentViewController:_mapViewController animated:YES completion:nil];
}

- (IBAction)changeSportState:(UIButton *)sender {
    //修改地图控制器的运动状态
    _mapViewController.sportTracking.sportState = sender.tag;
}
#pragma mark - 设置地图控制器
- (void)setMapViewController {
    
    //通过 sb 实例化视图控制器
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"ZYSportSporting" bundle:nil];
        _mapViewController = [sb instantiateViewControllerWithIdentifier:@"sportMapViewController"];
    //设置运动类型
    _mapViewController.sportTracking = [[ZYSportTracking alloc] initWithType:_sportType state:ZYSportStateContinue];
}

@end
